using System;
using System.Reflection;

public class ExecuteCommand
{
    public static bool IsRuleJudgeDll(byte[] buffer, double version, int projectType, string[] targets, int[] channels, int[] tubes, out string errorMsg)
    {
        errorMsg = null;
        try
        {
            Assembly assembly = Assembly.Load(buffer);
            Type type = assembly.GetType("RuleJudge.RuleJudge");
            object obj = Activator.CreateInstance(type);
            MethodInfo method = type.GetMethod("Judge");
            if (method == null)
            {
                return false;
            }
            method = type.GetMethod("GetResult");
            if (method == null)
            {
                return false;
            }
            method = type.GetMethod("Validate");
            if (method == null)
            {
                return false;
            }
            object obj2 = method.Invoke(obj, new object[5] { version, projectType, targets, channels, tubes });
            if (obj2 != null)
            {
                errorMsg = obj2.ToString();
                if (!string.IsNullOrEmpty(errorMsg))
                {
                    return false;
                }
            }
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

    public static int RunRuleJudge(byte[] buffer, object param, out string errorMsg, out object result)
    {
        errorMsg = null;
        result = null;
        try
        {
            Assembly assembly = Assembly.Load(buffer);
            Type type = assembly.GetType("RuleJudge.RuleJudge");
            object obj = Activator.CreateInstance(type);
            MethodInfo method = type.GetMethod("Judge");
            object obj2 = method.Invoke(obj, new object[1] { param });
            if (obj2 != null)
            {
                errorMsg = obj2.ToString();
            }
            if (string.IsNullOrEmpty(errorMsg))
            {
                method = type.GetMethod("GetResult");
                result = method.Invoke(obj, null);
            }
            return 1;
        }
        catch (Exception)
        {
            return 0;
        }
    }

    public static bool RuleJudgeNeedIndexData(byte[] buffer)
    {
        try
        {
            Assembly assembly = Assembly.Load(buffer);
            Type type = assembly.GetType("RuleJudge.RuleJudge");
            object obj = Activator.CreateInstance(type);
            MethodInfo method = type.GetMethod("NeedIndexData");
            return (bool)method.Invoke(obj, new object[0]);
        }
        catch (Exception)
        {
            return false;
        }
    }

    public static bool NeedCheckOrder(byte[] buffer)
    {
        try
        {
            Assembly assembly = Assembly.Load(buffer);
            Type type = assembly.GetType("RuleJudge.RuleJudge");
            object obj = Activator.CreateInstance(type);
            MethodInfo method = type.GetMethod("NeedCheckOrder");
            return (bool)method.Invoke(obj, new object[0]);
        }
        catch (Exception)
        {
            return false;
        }
    }

    public static string RunCheckOrder(byte[] buffer, object param)
    {
        try
        {
            Assembly assembly = Assembly.Load(buffer);
            Type type = assembly.GetType("RuleJudge.RuleJudge");
            object obj = Activator.CreateInstance(type);
            MethodInfo method = type.GetMethod("CheckOrder");
            return (string)method.Invoke(obj, new object[1] { param });
        }
        catch (Exception)
        {
            return string.Empty;
        }
    }

    public static string GetVersion(byte[] buffer)
    {
        try
        {
            Assembly assembly = Assembly.Load(buffer);
            Type type = assembly.GetType("RuleJudge.RuleJudge");
            object obj = Activator.CreateInstance(type);
            MethodInfo method = type.GetMethod("GetVersion");
            return (string)method.Invoke(obj, new object[0]);
        }
        catch (Exception)
        {
            return string.Empty;
        }
    }
}
